{% extends "base.html" %}

{% block breadcrumb_current %}
    超级管理员 > 新增地市管理员
{% endblock %}

{% block content %}
    <!-- 消息提示 -->
    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        {% endfor %}
    {% endif %}

<div class="container" style="margin-top: 50px;">

    <form method="POST" novalidate>
        {% csrf_token %}
        <div class="form-section">
            <h4 class="mb-3">用户信息</h4>
            <div class="row">
                <div class="col-md-3 mb-3">
                    <label for="{{ form.username.id_for_label }}" class="form-label required">账号</label>
                    {{ form.username }}
                    {% if form.username.errors %}
                        <div class="invalid-feedback">{{ form.username.errors|join:", " }}</div>
                    {% endif %}
                </div>

                <div class="col-md-3 mb-3">
                    <label for="{{ form.realname.id_for_label }}" class="form-label required">姓名</label>
                    {{ form.realname }}
                    {% if form.realname.errors %}
                        <div class="invalid-feedback">{{ form.realname.errors|join:", " }}</div>
                    {% endif %}
                </div>

                <div class="col-md-3 mb-3">
                    <label for="{{ form.phone_number.id_for_label }}" class="form-label required">手机号</label>
                    {{ form.phone_number }}
                    {% if form.phone_number.errors %}
                        <div class="invalid-feedback">{{ form.phone_number.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            <div class="row">
                <div class="col-md-3 mb-3">
                    <label for="{{ form.password1.id_for_label }}" class="form-label required">密码</label>
                    {{ form.password1 }}
                    {% if form.password1.errors %}
                        <div class="invalid-feedback">{{ form.password1.errors|join:", " }}</div>
                    {% endif %}
                </div>

                <div class="col-md-3 mb-3">
                    <label for="{{ form.password2.id_for_label }}" class="form-label required">确认密码</label>
                    {{ form.password2 }}
                    {% if form.password2.errors %}
                        <div class="invalid-feedback">{{ form.password2.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
            <div class="row">

                <div class="col-md-3 mb-3">
                    <label for="{{ form.department.id_for_label }}" class="form-label required">所属县区</label>
                    {{ form.department }}
                    {% if form.department.errors %}
                        <div class="invalid-feedback">{{ form.department.errors|join:", " }}</div>
                    {% endif %}
                </div>

                <div class="col-md-3 mb-3">
                    <label for="{{ form.company.id_for_label }}" class="form-label required">所属地市</label>
                    {{ form.company }}
                    {% if form.company.errors %}
                        <div class="invalid-feedback">{{ form.company.errors|join:", " }}</div>
                    {% endif %}
                </div>
            </div>
        </div>

        <div class="form-section">
            <h4 class="mb-3">管理员的权限</h4>
            <div class="row">
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.is_manager }}
                        <label for="{{ form.is_manager.id_for_label }}" class="form-check-label">管理员</label>
                    </div>
                </div>
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.is_broad }}
                        <label for="{{ form.is_broad.id_for_label }}" class="form-check-label">管理全部县区</label>
                    </div>
                </div>
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.is_approver }}
                        <label for="{{ form.is_approver.id_for_label }}" class="form-check-label">有审批权限</label>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.is_deviceoperator }}
                        <label for="{{ form.is_deviceoperator.id_for_label }}" class="form-check-label">有设备操作权限</label>
                    </div>
                </div>
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.is_inventoryoperator }}
                        <label for="{{ form.is_inventoryoperator.id_for_label }}" class="form-check-label">有库存操作权限</label>
                    </div>
                </div>
                <div class="col-md-4 mb-3">
                    <div class="form-check">
                        {{ form.can_add_device}}
                        <label for="{{ form.can_add_device.id_for_label }}" class="form-check-label">有新增设备权限</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" style="margin-top: 40px;">
            <div class="col-md-12 text-center">
                <a href="{% url 'navigation' %}" class="btn btn-secondary">取消</a>
                <button type="submit" class="btn btn-primary ms-2">保存</button>
            </div>
        </div>
    </form>
</div>

{% endblock %}